package com.kingyea.mobilepolice.apimanage.serverapimonitor.service.impl;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps;
import com.kingyea.mobilepolice.apimanage.serverapimonitor.bean.ServerApiMonitor;
import com.kingyea.mobilepolice.apimanage.serverapimonitor.dao.ServerApiMonitorMapper;
import com.kingyea.mobilepolice.apimanage.serverapimonitor.service.ServerApiMonitorService;
import com.kingyea.mobilepolice.apimanage.sysvo.bean.AllCondition;
import com.kingyea.mobilepolice.apimanage.utils.page.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Mr.Lin
 * @version v1.0.0
 * @description ServerApiMonitor 实现类
 * @date Created in 2018-05-19 14:08:21
 */
@Service
@Transactional
public class ServerApiMonitorServiceImpl implements ServerApiMonitorService {

    private static final Logger LOGGER = LoggerFactory.getLogger(ServerApiMonitorServiceImpl.class);

    @Resource
    private ServerApiMonitorMapper serverApiMonitorMapper;

    /**
     * 通过ID查找对象
     *
     * @param id
     * @return
     */
    @Override
    public ServerApiMonitor getById(Integer id) {
        return this.serverApiMonitorMapper.getById(id);
    }

    /**
     * 列表
     *
     * @param
     * @return
     */
    @Override
    public List<ServerApiMonitor> list(AllCondition condition) {
        List<ServerApiMonitor> list = serverApiMonitorMapper.list(condition);
        return list;
    }

    @Override
    public PageInfo<List<ServerApiMonitor>> search(AllCondition condition) throws Exception {
//		List<ServerApiMonitor> list = serverApiMonitorMapper.list(condition);
        PageInfo.startPage(JSON.parseObject(JSON.toJSONString(condition), Maps.<String, Object>newHashMap().getClass()));
        return PageInfo.getPageInfo(serverApiMonitorMapper.searchGather(condition));
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Override
    public boolean deleteById(Integer id) {
        return serverApiMonitorMapper.deleteById(id) == 1;
    }

    /**
     * 保存
     *
     * @param serverApiMonitor
     * @return
     */
    @Override
    public boolean save(ServerApiMonitor serverApiMonitor) {
        return serverApiMonitorMapper.save(serverApiMonitor) == 1;
    }

    /**
     * 更新
     *
     * @param serverApiMonitor
     * @return
     */
    @Override
    public boolean update(ServerApiMonitor serverApiMonitor) {
        return serverApiMonitorMapper.update(serverApiMonitor) == 1;
    }


}
